// Copyright (C) 2002-2010 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h

#ifndef __C_CAMERA_CONTROLER_H_INCLUDED__
#define __C_CAMERA_CONTROLER_H_INCLUDED__

#include "ISceneNodeAnimatorCameraFPS.h"
#include "vector2d.h"
#include "position2d.h"
#include "SKeyMap.h"
#include "irrArray.h"
#include "ICameraSceneNode.h"

namespace irr
{
	namespace gui
	{
		class ICursorControl;
	}

	namespace scene
	{

		//! Special scene node animator for FPS cameras
		class CameraControler : public ISceneNodeAnimator
		{
		public:

			//! Constructor
			CameraControler(gui::ICursorControl* cursorControl,
				ISceneManager* smgr, f32 rotateSpeed = 100.0f, bool invertY=false);

			//! Destructor
			virtual ~CameraControler();

			//! Animates the scene node, currently only works on cameras
			virtual void animateNode(ISceneNode* node, u32 timeMs);

			//! Event receiver
			virtual bool OnEvent(const SEvent& event);

			//! Returns the rotation speed
			virtual f32 getRotateSpeed() const;

			//! Set the rotation speed
			virtual void setRotateSpeed(f32 rotateSpeed);

			//! Sets whether the Y axis of the mouse should be inverted.
			/** If enabled then moving the mouse down will cause
			the camera to look up. It is disabled by default. */
			virtual void setInvertMouse(bool invert);

			//! This animator will receive events when attached to the active camera
			virtual bool isEventReceiverEnabled() const
			{
				return true;
			}

			//! Returns the type of this animator
			virtual ESCENE_NODE_ANIMATOR_TYPE getType() const
			{
				return ESNAT_UNKNOWN;
			}

			//! Creates a clone of this animator.
			/** Please note that you will have to drop
			(IReferenceCounted::drop()) the returned pointer once you're
			done with it. */
			virtual ISceneNodeAnimator* createClone(ISceneNode* node, ISceneManager* newManager=0);

		private:

			ISceneManager* manager;
			gui::ICursorControl *CursorControl;
			ICameraSceneNode* camera;

			f32 MaxVerticalAngle;

			f32 RotateSpeed;
			// -1.0f for inverted mouse, defaults to 1.0f
			f32 MouseYDirection;

			s32 LastAnimationTime;

			core::position2d<s32> then, now;

			bool firstUpdate;
			bool hasPressedDown,directionPrepared,useLeftMouse;

		};

	} // end namespace scene
} // end namespace irr

#endif // __C_CAMERA_CONTROLER_H_INCLUDED__

